package com.lizemin.annotation;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Proxy;

/**
 * @author lzm
 * @date 2025/4/21 20:36
 * @description
 */
@Slf4j
public class FeignClientProxy {

    /**
     * 获取接口的代理对象
     *
     * @param clazz 接口类
     * @return 代理对象
     * @param <T> 泛型
     */
    @SuppressWarnings("unchecked")
    public static <T> T getProxy(Class<T> clazz) {
        if (!clazz.isInterface()) {
            throw new RuntimeException("请传入接口类型的class");
        }
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(),
                new Class[]{clazz},
                new SimpleFeignClientAspect(clazz)
        );
    }


}
